package com.videoaggre.zcl.ui.activity.qiman

import androidx.recyclerview.widget.GridLayoutManager
import com.videoaggre.zcl.R
import com.videoaggre.zcl.api.QIMAN_SERVICE
import com.videoaggre.zcl.bean.QimanComicHomeNormal
import com.videoaggre.zcl.common.getString
import com.videoaggre.zcl.common.showEmptyCallback
import com.videoaggre.zcl.parse.impl.QimanParse
import com.videoaggre.zcl.ui.activity.BaseRefreshActivity
import com.videoaggre.zcl.ui.activity.launchUI
import com.videoaggre.zcl.utils.Utils
import kotlinx.android.synthetic.main.activity_base_refresh.*
import kotlinx.android.synthetic.main.agefans_activity_search.*

class QimanSearchActivity : BaseRefreshActivity<QimanComicHomeNormal>(R.layout.agefans_activity_search) {
    private val mQimanComicRecommendAdapter: QimanComicRecommendAdapter = QimanComicRecommendAdapter()
    override fun initView() {
        svSearch.hint = R.string.qiman_text_search.getString()
        svSearch.clearListener = ::onReload
        mBaseRecyclerAdapter = mQimanComicRecommendAdapter
        super.initView()
        refreshLayout.setEnableLoadMore(false)
        recyclerView.layoutManager = GridLayoutManager(this, 2)
    }

    override fun initData() {
        mRefreshHelper.mLoadService?.showEmptyCallback()
    }

    override fun onReload() {
        Utils.hideSoftInput(this)
        if (svSearch.text.isNotEmpty()) {
            launchUI({ QimanParse.parseSearch(QIMAN_SERVICE.spotlight(svSearch.text)) }, mRefreshHelper.handApiObserver())
        }
    }
}